﻿<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

	<head>
		<meta charset="UTF-8"></meta>
		<title>管理员查询</title>
		<link rel="stylesheet" th:href="@{/plugins/layui/css/layui.css}" media="all" />
		<link rel="stylesheet" th:href="@{/css/global.css}" media="all"/>
		<link rel="stylesheet" th:href="@{/plugins/font-awesome/css/font-awesome.min.css}"/>
		<link rel="stylesheet" th:href="@{/css/table.css}" />
	</head>

	<body>
            <div class="admin-main">
            
            
					
				
			 <form class="layui-form" action="">
	               <fieldset class=" layui-elem-quote">
	               
					<div class="layui-form-item layui-footer">
						<div class="layui-inline">
							<label class="layui-form-label">企业名称：</label>
							<div class="layui-input-inline">
								<input type="text" name="enterpriseName" id="enterpriseName" class="layui-input"/>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">企业状态：</label>
							<div class="layui-input-inline">
								  <select name="enterpriseStatus" lay-filter="aihao">
                                        <option value="">请选择企业状态</option>
                                        <option value="1">在用</option>
                                        <option value="2">禁用</option>
                                  </select>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">企业类型：</label>
							<div class="layui-input-inline">
								  <select name="instanceType" lay-filter="aihao">
                                        <option value="">请选择企业类型</option>
                                        <option value="1">普通</option>
                                        <option value="2">预收货款</option>
                                  </select>
							</div>
						</div>
			            <a href="javascript:;" class="layui-btn" id="search" onclick="searchEnterprise()">
							<i class="layui-icon">&#xe615;</i> 搜索
						</a> 
					</div>
	
					
					<div class="layui-form-item">
						
						<a href="javascript:;" class="layui-btn " id="search" onclick="add()">
							 添加企业
						</a>
					</div>
					
					</fieldset>
				</form>
			
			
			
			
			
			<fieldset class="layui-elem-field" id="enterpriseTableSet">
				
				<table class="layui-hide" id="enterprise" lay-filter="enterprise"></table>
				
			</fieldset>
				
			  
        </div>
        
        
               <script th:src="@{/js/jquery.min.js?v=2.1.4}"></script>
		        <script type="text/javascript" th:src="@{/plugins/layui/layui.js}"></script>
     	       <script type="text/html" id="barDemo">
                   <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
                   <a class="layui-btn layui-btn-sm" lay-event="change">重置密码</a>
                   <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
           </script>
       
       <script type="text/javascript">
		$(function() {
			//searchRole()
			loadEnterpriseTable();
		});
            
    		function getEnterpriseName() {
    			let enterpriseName = $("input#enterpriseName").val()
    			return enterpriseName
    		} 
     		function getEnterpriseStatus() {
    			let enterpriseStatus = $("select#enterpriseStatus").val()
    			return enterpriseStatus
    		} 
    		function getInstanceType() {
    			let instanceType = $("select#instanceType").val()
    			return instanceType
    		} 

function add() {
	// iframe层
	layer.open({
		type : 2,
		title : '添加管理员',
		maxmin : true,
		shadeClose : false, // 点击遮罩关闭层
		area : [ '800px', '460px' ],
		content :  '/merchant/enterprise/addEnterprise'// iframe的url
	});
}


function searchEnterprise() {
	// alert('ready to search')
	clearEnterpriseTable()
	loadEnterpriseTable()
}

function clearEnterpriseTable() {
	let tableSet = document.getElementById("enterpriseTableSet")
	
	var childs = tableSet.childNodes;
	
	console.log('tableSet.childNodes length:' + childs.length)
	

	childs.forEach(function(value,index,array){
		tableSet.removeChild(array[index])
	});
	
	tableSet.removeChild(tableSet.firstChild)

	var para=document.createElement("table");
	para.setAttribute("id", "enterprise")
	para.setAttribute("lay-filter", "enterprise")
	tableSet.appendChild(para)

}
function loadEnterpriseTable () {
	layui.use(['table','jquery'], function(){
	    var table = layui.table,
	    $ =layui.jquery;  
	    //第一个实例
	    table.render({
	      elem: '#enterprise'
	      ,height: 375
	      ,url: '/merchant/enterprise/list' //数据接口
	      ,page: true //开启分页
		  ,where: { //设定异步数据接口的参数
			  enterpriseName: getEnterpriseName(),
			  enterpriseStatus:getEnterpriseStatus(),
			  instanceType:getInstanceType()
			}
	      ,limit:10   //默认十条数据一页
	      ,limits:[10,20,30,50]  //数据分页条
	      ,cols: [[ //表头
	        {field: 'enterpriseName', title: '企业名称', width:200, sort: true, fixed: 'left'}
	        ,{field: 'instanceId', title: '企业编码', width:120}
	        ,{field: 'paymentId', title: '企业活动码', width:120}
	        ,{field: 'demandCycTypeStr', title: '结算周期', width:120}
	        ,{field: 'demandCycDay', title: '活期结算日', width:120}
	        ,{field: 'merId', title: '商户号', width:160}
	        ,{fixed: 'right',title: '操作' ,minwidth:210, align:'center', toolbar: '#barDemo'}
	      ]]
	    });
	   
	    var frameindex = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
	    //监听工具条
	    table.on('tool(enterprise)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
	      var data = obj.data ,//获得当前行数据
	      layEvent = obj.event; //获得 lay-event 对应的值
	      if(layEvent === 'change'){
	      	 layer.open({
	               type: 2,
	               title: '重置密码',
	               shadeClose: true,
	               shade: 0.3,
	               area: ['600px', '420px'],
	               content: '/merchant/setting/changePassWord?userAccount='+data.userAccount,
	           });
	      } else if(layEvent === 'del'){
	        layer.confirm('真的删除行么', function(index){	        	
	            var url = '/merchant/setting/delete';
	            $.post(url, {userAccount : data.userAccount}, function (ev) {
	                if (ev.code == 000000) {
	                    layer.msg(ev.msg);
	                    loadManagerTable();
	                } else {
	                    layer.close(index);
	                    layer.msg(ev.msg);
	                }
	            }, 'json')
	            //发送ajax
	            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。  
	          
	          //向服务端发送删除指令
	        });
	      } else if(layEvent === 'edit'){
	          layer.open({
	              type: 2,
	              title: '修改管理员',
	              shadeClose: true,
	              shade: 0.3,
	              area: ['600px', '420px'],
	              content: '/merchant/setting/modifyManager?userAcct='+data.userAccount,
	          });
	      }
	    });
	    
	  });	
}

</script>
</body>
</html>